//
//  RootViewController.m
//  atXiaoGeBClient
//
//  Created by Linyu Niu on 12/04/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBarHidden = YES;
}

-(void)startLoadingView:(UIView *)view{
    
    if (view) {
        [MBProgressHUD wj_showActivityLoadingToView:view];
    }else{
        [MBProgressHUD wj_showActivityLoadingToView:self.view];
    }
}
-(BOOL)stopLoadingView:(UIView *)view needShowMsg:(BOOL)showMsg result:(NSDictionary *)result{
    if (view) {
        [MBProgressHUD wj_hideHUDForView:view];
    }else{
        [MBProgressHUD wj_hideHUDForView:self.view];
    }
    
    BOOL success = [self isSuccess:result];
    if (showMsg) {
        NSString * msg = [result objectForKey:@"msg"];
        if (success) {
            [MBProgressHUD wj_showSuccess:msg];
        }else{
            [MBProgressHUD wj_showError:msg];
        }

    }else{
        
    }
    return success;
}
-(BOOL)isSuccess:(NSDictionary *)result{
    NSString * resultString = [result objectForKey:@"result"];
    NSInteger code = [[result objectForKey:@"code"] integerValue];
    
    if (code == 10000 || [resultString isEqualToString:@"success"]) {
        return YES;
    }
    return NO;
}
-(void)addEmptyView:(UIView *)view list:(NSArray *)list imgName:(NSString *)imgName{
    [[view viewWithTag:0x0099] removeFromSuperview];
    if (![view viewWithTag:0x0099] && ![list count]) {
        UIImageView * emptyImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgName]];
        emptyImgView.tag = 0x0099;
        emptyImgView.contentMode = UIViewContentModeScaleAspectFit;
        emptyImgView.frame = CGRectMake(0, 100, view.frame.size.width, 100);
        [view addSubview:emptyImgView];
    }
}


-(UITableView *)addTableViewInView:(UIView *)view frame:(CGRect)frame delegateAndDataSource:(id<UITableViewDelegate,UITableViewDataSource>)delegateAndDataSource{
    UITableView * tableView = [[UITableView alloc]initWithFrame:frame];
    tableView.backgroundColor = [UIColor clearColor];
    tableView.delegate = delegateAndDataSource;
    tableView.dataSource = delegateAndDataSource;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [view addSubview:tableView];
    return tableView;
}


-(void)setRichLabelWithNumber:(NSString *)number unit:(NSString *)unit numberColor:(UIColor *)numberColor textColor:(UIColor *)txtColor fontSize:(float)fontSize numberSize:(float)numberSize label:(UILabel *)label{
    NSString * string = [NSString stringWithFormat:@"%@ %@",number,unit];
    
    NSMutableAttributedString * richString = [[NSMutableAttributedString alloc]initWithString:string];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.alignment = NSTextAlignmentCenter;
    [paragraphStyle setLineSpacing:5.0];//调整行间距
    
    [richString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];
    [richString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:fontSize] range:[string rangeOfString:unit]];
    [richString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:numberSize] range:[string rangeOfString:number]];
    if (numberColor) {
        [richString addAttribute:NSForegroundColorAttributeName value:numberColor range:[string rangeOfString:number]];
    }else{
        [richString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x20C67A) range:[string rangeOfString:number]];
    }
    if (txtColor) {
        [richString addAttribute:NSForegroundColorAttributeName value:txtColor range:[string rangeOfString:unit]];
    }else{
        [richString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x333333) range:[string rangeOfString:unit]];
    }
    
    
    label.attributedText = richString;
}
@end
